# -*- coding: utf-8 -*-
"""
@Time    : 2024/8/1 15:03 
@Author  : ZhangShenao 
@File    : 4.自定义状态码和响应头.py 
@Desc    : 自定义状态码和响应头
"""
import json

from flask import Flask, Response

app = Flask(__name__)
app.config["DEBUG"] = True


@app.route("/custom_response_header", methods=["GET"])
def custom_response_header() -> [str | Response]:
    """自定义响应头和状态码"""

    # 构造响应数据
    data = {
        "name": "zsa",
        "age": 18,
    }

    # 构造自定义Response Header
    headers = {
        "Content-Type": "application/json",
        "Author": "zsa",  # 自定义Response Header
    }

    return Response(json.dumps(data), status=200, headers=headers)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
